package com.VitalFit.model.entity;

import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;
import jakarta.persistence.*;
import lombok.Data;

import java.time.LocalDateTime;

@Entity
@Data
@Table(name = "appointment", indexes = {
        @Index(name = "idx_start_date_time", columnList = "startDateTime"),
        @Index(name = "idx_end_date_time", columnList = "endDateTime")
})
public class Appointment {

    @Id
    private Long id;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "customer_id")
    private Customer customer;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "trainer_id")
    private Trainer trainer;

    private LocalDateTime startDateTime;

    private LocalDateTime endDateTime;

    public Appointment() {
        // 使用 Hutool 的 Snowflake 生成 ID
        Snowflake snowflake = IdUtil.getSnowflake(1, 1);
        this.id = snowflake.nextId();
    }
}
